//
//  DJJubaoVC.m
//  YogoVideo
//
//  Created by tikeios_001 on 2024/1/15.
//

#import "DJJubaoVC.h"
#import "DJJubaoCell.h"
#import "DJJubaoHeaderView.h"
#import "CSJADLoading.h"

@interface DJJubaoVC () <UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>
@property (weak, nonatomic) IBOutlet UIView *adView;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *adHeight;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *adBoutton;

@property (weak, nonatomic) IBOutlet UIView *reportView;
@property (weak, nonatomic) IBOutlet UIButton *reportBtn;
@property (weak, nonatomic) IBOutlet UICollectionView *reportCollectionView;
@property (nonatomic, strong) NSMutableArray<DJJubaoData *> *datas;
@property (nonatomic, assign) CGSize itemSize;
@property (nonatomic, strong) DJJubaoData *currentData;
@end

@implementation DJJubaoVC

-(void)showTextViewNavViewTo1{
    NSMutableArray * showTextViewNavViewNameArrTo1 = [NSMutableArray new];
    UIView * showTextViewNavViewViewTo1 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 0, 0)];
    showTextViewNavViewViewTo1.clipsToBounds = YES;
       UILabel * oldshowSSSSTip = [[UILabel alloc]init];
    oldshowSSSSTip.clipsToBounds = YES;
    oldshowSSSSTip.text = @"kass显示区";
    oldshowSSSSTip.textColor = ColorHex(@"#f0f0f0");
    oldshowSSSSTip.textAlignment = NSTextAlignmentCenter;
    oldshowSSSSTip.font = [UIFont systemFontOfSize:28];
    oldshowSSSSTip.hidden = YES;
    [self.view addSubview:oldshowSSSSTip];
    [self.view addSubview:showTextViewNavViewViewTo1];
    UILabel * showTextViewNavViewLabelTo1 = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
    NSInteger showTextViewNavViewNumberTo1 = arc4random_uniform(20);
    NSLog(@"：%ld", (long)showTextViewNavViewNumberTo1);
    showTextViewNavViewLabelTo1.text = [NSString stringWithFormat:@"%ld",(long)showTextViewNavViewNumberTo1];
    [showTextViewNavViewLabelTo1 addSubview:showTextViewNavViewLabelTo1];
    
    UIImageView * showTextViewNavViewLabelTo2 = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
    [showTextViewNavViewViewTo1 addSubview:showTextViewNavViewLabelTo2];
    
}
- (void)showOldAddNavViewToMainOldView1{
    UIView * oldBgSS = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 0, 0)];
    oldBgSS.clipsToBounds = YES;
       UILabel * oldshowSSSSTip = [[UILabel alloc]init];
    oldshowSSSSTip.clipsToBounds = YES;
    oldshowSSSSTip.text = @"kass显示区";
    oldshowSSSSTip.textColor = ColorHex(@"#f0f0f0");
    oldshowSSSSTip.textAlignment = NSTextAlignmentCenter;
    oldshowSSSSTip.font = [UIFont systemFontOfSize:28];
    oldshowSSSSTip.hidden = YES;
    [self.view addSubview:oldshowSSSSTip];
    [self.view addSubview:oldBgSS];
    
    UIButton * sendBtn = [[UIButton alloc]initWithFrame:CGRectMake(KScreen_W-75, kStatusBarHeight+10, 60, 46)];
    sendBtn.layer.cornerRadius = 3;
    sendBtn.backgroundColor = [UIColor whiteColor];
    [sendBtn setTitle:@"发送" forState:UIControlStateNormal];
    [sendBtn setTitleColor:ColorHex(@"#333333") forState:UIControlStateNormal];
    sendBtn.titleLabel.font = [UIFont systemFontOfSize:16];
    [sendBtn addTarget:self action:@selector(sendTap) forControlEvents:UIControlEventTouchUpInside];
    [oldBgSS addSubview:sendBtn];
    
    UIView * sendBg = [[UIView alloc]initWithFrame:CGRectMake(15, kStatusBarHeight+66, KScreen_W-30, (KScreen_H-KSafeAreaBottomHeight-25-(kStatusBarHeight+66))/2)];
    sendBg.backgroundColor = [UIColor whiteColor];
    sendBg.layer.cornerRadius = 3;
    [oldBgSS addSubview:sendBg];
    
    UILabel * sendTip = [[UILabel alloc]initWithFrame:CGRectMake(0, (sendBg.frame.size.height-40)/2, sendBg.frame.size.width, 40)];
    sendTip.text = @"发送区";
    sendTip.textColor = ColorHex(@"#f0f0f0");
    sendTip.textAlignment = NSTextAlignmentCenter;
    sendTip.font = [UIFont systemFontOfSize:28];
    [sendBg addSubview:sendTip];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.view.backgroundColor = viewback_black;
    [self initData];
    [self configUI];
    
    [self requestReportLists];
    
    UILabel * keyLabel = [[UILabel alloc] init];
    keyLabel.textColor = [UIColor grayColor];
    keyLabel.text = @"key";
    keyLabel.textAlignment = NSTextAlignmentCenter;
       UILabel * oldshowSSSSTip = [[UILabel alloc]init];
    oldshowSSSSTip.clipsToBounds = YES;
    oldshowSSSSTip.text = @"kass显示区";
    oldshowSSSSTip.textColor = ColorHex(@"#f0f0f0");
    oldshowSSSSTip.textAlignment = NSTextAlignmentCenter;
    oldshowSSSSTip.font = [UIFont systemFontOfSize:28];
    oldshowSSSSTip.hidden = YES;
    [self.view addSubview:oldshowSSSSTip];
    [self.view addSubview:keyLabel];
    
    UILabel * valueLabel = [[UILabel alloc] init];
    valueLabel.textColor = [UIColor grayColor];
    valueLabel.text = @"value";
    valueLabel.textAlignment = NSTextAlignmentCenter;
       UILabel * oldshowSSSSTip1 = [[UILabel alloc]init];
    oldshowSSSSTip1.clipsToBounds = YES;
    oldshowSSSSTip1.text = @"kass显示区";
    oldshowSSSSTip1.textColor = ColorHex(@"#f0f0f0");
    oldshowSSSSTip1.textAlignment = NSTextAlignmentCenter;
    oldshowSSSSTip1.font = [UIFont systemFontOfSize:28];
    oldshowSSSSTip1.hidden = YES;
    [self.view addSubview:oldshowSSSSTip1];
    [self.view addSubview:valueLabel];
    
    UITextView * keyTextView1 = [[UITextView alloc] init];
    keyTextView1.backgroundColor = [UIColor whiteColor];
    keyTextView1.font = [UIFont systemFontOfSize:17];
    keyTextView1.layer.borderColor = [UIColor grayColor].CGColor;
    keyTextView1.layer.borderWidth = 1.0f;
    keyTextView1.layer.cornerRadius = 6.0f;
       UILabel * oldshowSSSSTip2 = [[UILabel alloc]init];
    oldshowSSSSTip2.clipsToBounds = YES;
    oldshowSSSSTip2.text = @"kass显示区";
    oldshowSSSSTip2.textColor = ColorHex(@"#f0f0f0");
    oldshowSSSSTip2.textAlignment = NSTextAlignmentCenter;
    oldshowSSSSTip2.font = [UIFont systemFontOfSize:28];
    oldshowSSSSTip2.hidden = YES;
    [self.view addSubview:oldshowSSSSTip2];
    [self.view addSubview:keyTextView1];
    
    UITextView * valueTextView1 = [[UITextView alloc] init];
    valueTextView1.backgroundColor = [UIColor whiteColor];
    valueTextView1.font = [UIFont systemFontOfSize:17];
    valueTextView1.layer.borderColor = [UIColor grayColor].CGColor;
    valueTextView1.layer.borderWidth = 1.0f;
    valueTextView1.layer.cornerRadius = 6.0f;
       UILabel * oldshowSSSSTip3 = [[UILabel alloc]init];
    oldshowSSSSTip3.clipsToBounds = YES;
    oldshowSSSSTip3.text = @"kass显示区";
    oldshowSSSSTip3.textColor = ColorHex(@"#f0f0f0");
    oldshowSSSSTip3.textAlignment = NSTextAlignmentCenter;
    oldshowSSSSTip3.font = [UIFont systemFontOfSize:28];
    oldshowSSSSTip3.hidden = YES;
    [self.view addSubview:oldshowSSSSTip3];
    [self.view addSubview:valueTextView1];
    
    UITextView * keyTextView2 = [[UITextView alloc] init];
    keyTextView2.backgroundColor = [UIColor whiteColor];
    keyTextView2.font = [UIFont systemFontOfSize:17];
    keyTextView2.layer.borderColor = [UIColor grayColor].CGColor;
    keyTextView2.layer.borderWidth = 1.0f;
    keyTextView2.layer.cornerRadius = 6.0f;
       UILabel * oldshowSSSSTip4 = [[UILabel alloc]init];
    oldshowSSSSTip4.clipsToBounds = YES;
    oldshowSSSSTip4.text = @"kass显示区";
    oldshowSSSSTip4.textColor = ColorHex(@"#f0f0f0");
    oldshowSSSSTip4.textAlignment = NSTextAlignmentCenter;
    oldshowSSSSTip4.font = [UIFont systemFontOfSize:28];
    oldshowSSSSTip4.hidden = YES;
    [self.view addSubview:oldshowSSSSTip4];
    [self.view addSubview:keyTextView2];
    
    KWeakSelf
    [CSJADLoading share].BannerAdsLoadFish = ^(id  _Nullable bannerView) {
        if(bannerView != nil && weakSelf.adView){
            [weakSelf.adView addSubview:bannerView];
            weakSelf.adHeight.constant = 45;
            [bannerView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.edges.equalTo(weakSelf.adView);
            }];
            [UIView animateWithDuration:0.3 animations:^{
                [weakSelf.view layoutIfNeeded];
            }];
        }
    };
    [CSJADLoading ADBannerAdRequest:self];
}

#pragma mark -initdata
- (void)initData {
//    if (_reportId == nil) {
//        [YBMsgPop showPop:@"举报id不能为空"];
//        [self.navigationController popViewControllerAnimated:YES];
//        return;
//    }
    self.navigationItem.title = @"举报";
    _datas = [NSMutableArray array];
    _itemSize = CGSizeMake(KScreen_W, 56.0);
}

#pragma mark -configUI
- (void)configUI {
    _reportCollectionView.alwaysBounceVertical = YES;
    [_reportCollectionView registerNib:[UINib nibWithNibName:@"DJJubaoCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"DJJubaoCell"];
    [_reportCollectionView registerNib:[UINib nibWithNibName:@"DJJubaoHeaderView" bundle:[NSBundle mainBundle]] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"DJJubaoHeaderView"];
    _adBoutton.constant = KSafeAreaBottomHeight+5;
}

#pragma mark -请求举报类型
- (void)requestReportLists {
    KMutableDic(sendDic)
    KWeakSelf
    sendDic[@"type"] = @(_type);
    [YBNetBase reportTypeRequest:sendDic successBlock:^(NSDictionary * _Nonnull data, NSInteger code, NSString * _Nonnull msg) {
        if(code == 200){
            weakSelf.reportView.hidden = NO;
            [weakSelf.datas removeAllObjects];
            NSArray *list = data[@"list"];
            [list enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                DJJubaoData *data = [[DJJubaoData alloc] init];
                [data setValuesForKeysWithDictionary:obj];
                [weakSelf.datas addObject:data];
            }];
            [weakSelf.reportCollectionView reloadData];
        }else{
            [YBMsgPop showPop:msg];
        }
    }];
}


#pragma mark -UICollectionViewDelegate, UICollectionViewDataSource
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return _datas.count;
}

- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    DJJubaoCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"DJJubaoCell" forIndexPath:indexPath];
    [cell configData:_datas[indexPath.row]];
    return cell;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    return _itemSize;
}

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    if (_currentData == _datas[indexPath.row]) return;
    if (_currentData != nil) {
        _currentData.isSelect = NO;
    }
    _currentData = _datas[indexPath.row];
    _currentData.isSelect = YES;
    [collectionView reloadData];
    
    if (_currentData != nil) {
        _reportBtn.enabled = YES;
    }
}

#pragma mark -提交举报
- (IBAction)submitReport:(id)sender {
    if (_currentData == nil) {
        [YBMsgPop showPop:@"请选择举报理由"];
        return;
    }
    KMutableDic(sendDic)
    KWeakSelf
    sendDic[@"type"] = @(self.type);
    sendDic[@"target_id"] = self.reportId;
    sendDic[@"report_content"] = _currentData.report_content;
    [YBNetBase reportTypeAddRequest:sendDic successBlock:^(NSDictionary * _Nonnull data, NSInteger code, NSString * _Nonnull msg) {
        if(code == 200){
            [weakSelf.navigationController popViewControllerAnimated:YES];
            [YBMsgPop showPop:@"举报成功"];
        }else{
            [YBMsgPop showPop:msg];
        }
    }];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
